package com.fyl.pattern.singleton.demo7;

import java.io.Serializable;

/**
 * 静态内部类方式
 */
public class Singleton implements Serializable {
    public Singleton() {
    }

    //静态内部类
    private static class SingletonHolder {
        private static final Singleton INSTANCE = new Singleton();
    }
    public static Singleton getInstance(){
        return SingletonHolder.INSTANCE;
    }

    //当进行序列化时，会自动调用该方法，将该方法的返回值直接返回
    public Object readResolve(){
        return SingletonHolder.INSTANCE;
    }
}
